package com.example.exp61.mapper

import com.baomidou.mybatisplus.core.mapper.BaseMapper
import com.example.exp61.model.dto.*
import com.example.exp61.model.entity.*
import org.apache.ibatis.annotations.*

@Mapper
interface SysUserMapper : BaseMapper<SysUser> {

    @Select("select * from sys_user where id = #{userId}")
    fun getSysUserById(userId: Int): SysUser

    @Select("select * from user_info where user_id = #{userId}")
    fun listUserInfoById(userId: Int): List<UserInfo>

    @Results(
        id = "com.example.exp61.model.dto.UserDTO",
        value = [
            Result(property = "userId", column = "id", id = true),
            Result(property = "userName", column = "name"),
            Result(
                property = "userInfoList", column = "id",
                many = Many(select = "listUserInfoById")
            )]
    )
    @Select("select id, name from sys_user where id = #{id}")
    fun getUserDTOById(userId: Int): UserDTO

}